package q2210_countHillValley;

public class Solution {
    public static void main(String[] args) {
        Solution s = new Solution();
        int[] m = {2,4,1,1,6,5};
        s.countHillValley(m);
    }
    public int countHillValley(int[] nums) {
        int ans = 0;
        boolean isUphill = nums[0] < nums[1];
        boolean isDownhill = nums[0] > nums[1];
        for (int i = 2; i < nums.length; i++) {
            if (nums[i - 1] < nums[i]) {
                if (isDownhill) {
                    ans++;
                }
                isUphill = true;
                isDownhill = false;
            } else if (nums[i - 1] > nums[i]) {
                if (isUphill) {
                    ans++;
                }
                isUphill = false;
                isDownhill = true;
            }
        }
        return ans;
    }
}
